import java.util.Scanner;

public class langren {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("欢迎来到狼人杀游戏");

        String[] roles = {"狼人","狼人","平民","平民","平民"};
        int numPlayers = roles.length;
        boolean[] isAlive = new boolean[numPlayers];

        for (int i = 0; i < numPlayers; i++) {
            isAlive[i] = true;
        }
        boolean gameOver = false;
        while (!gameOver){

            System.out.println("\n当前存活玩家：");
            for (int i = 0; i < numPlayers; i++) {
                if (isAlive[i]){
                    System.out.println(i+":"+roles[i]);
                }
            }
           System.out.println("\n狼人请行动（输入要杀死的玩家编号）：");
            int wolfTarget = scanner.nextInt();

            if (roles[wolfTarget].equals("狼人")){
                System.out.println("不能杀死同伴！");
            }else {
                isAlive[wolfTarget] = false;
                System.out.println("玩家"+wolfTarget+"已被杀死。");
            }
              int numWolves = 0;
            int numVillagers = 0;
            for (int i = 0; i < numPlayers; i++) {
                if (isAlive[i]){
                    numWolves++;
                }else {
                    numVillagers++;
                }
            }
            if (numWolves > numVillagers){
                System.out.println("\n狼人胜利！");
                gameOver = true;
            }else if (numWolves ==0){
                System.out.println("\n村民胜利！");
                gameOver = true;
            }

            if (!gameOver){
                System.out.println("\n天亮了，请发言投票（输入要投票的玩家编号：）");
                int voteTarget = scanner.nextInt();
                if (isAlive[voteTarget]){
                    System.out.println("玩家"+voteTarget+"已被投票出局");
                    isAlive[voteTarget]=false;
                }else {
                    System.out.println("玩家已经死亡不存在！");
                }

                numWolves = 0;
                numVillagers = 0;

                for (int i = 0; i < numPlayers; i++) {
                    if (isAlive[i]){
                        if (roles[i].equals("狼人")){
                            numWolves++;
                        }else {numVillagers++;}
                    }
                }
            }

            if (numWolves >= numVillagers){
                System.out.println("\n狼人胜利！");

                gameOver = true;
            }else if(numWolves ==0){
                System.out.println("\n村民胜利！");
                gameOver= true;
            }
        }
System.out.println("\n游戏结束。再见！");
    }
}
